<!DOCTYPE html>
<html>
<head>
	<meta charset = "utf-8">
	<title>这事一个测试</title>
	<script type="text/javascript" src="cookie.js"></script>
	<script type="text/javascript">
	var userName;

	function resizeRock () {
		document.getElementById("rockImg").style.height = (document.body.clientHeight - 100) * 0.9;
	}

	function greetUser () {
		if (navigator.cookieEnabled) {
			userName = readCookie("irock_username");
		};
		if (userName)
			alert("hello " + userName + ", I missed you.");
		else
			alert('Hello, I am your pet rock.');
	}

	function touchRock () {
		if (userName) {
			alert("I like the attention," + userName + ".Thank you.");
		}else{
			userName = prompt("What is your name?", "Enter your name here.");
			if (userName) {
            alert("It is good to meet you, " + userName + ".");
            if (navigator.cookieEnabled)
              writeCookie("irock_username", userName, 5 * 365);
            else
              alert("Cookies aren't supported/enabled in your browser, which means I won't remember you later. I'm sorry.");
          }
		}
		document.getElementById("rockImg").src = "rock_happy.png";
        setTimeout("document.getElementById('rockImg').src = 'rock.png';", 0.5 * 60 * 1000);
	}
	</script>
</head>
<body onload="resizeRock(); greetUser();" onresize="resizeRock();">
	<div style="margin-top:100px; text-align:center">
      <img id="rockImg" src="rock.png" alt="iRock" style="cursor:pointer" onclick="touchRock();" />
    </div>
</body>
</html>